package com.ribbonprovider.provider.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * helloworld
 * <p/>
 *
 * @author zhangshuai
 * @version 1.0
 * @date 2021-5-8 9:24
 **/
@RestController
public class HelloWorldController {

    @Autowired
    private LoadBalancerClient loadBalancerClient;

    /**
     * 获取当前端口配置
     **/
    @Value("${server.port}")
    private String port;

    @GetMapping("/hello")
    public String helloWorld() {
        return "Hello World from port:" + port;
    }

    @GetMapping("/serviceInstance")
    public ServiceInstance serviceInstance() {
        return loadBalancerClient.choose("RIBBON-SERVICE");
    }

}
